<template>
  <div class="app-container flex-col minH">
    <div class="topline w100p bgwhite pt20 pb10 radius10 pl10 pr20 justify-between">
      <div>
        <el-input v-model="uid" style="width: 280px" placeholder="搜尋用戶ID..." :prefix-icon="Search" class="search mr10 mb10" />
        <el-input v-model="mobile" style="width: 280px" placeholder="搜尋手機號..." :prefix-icon="Search" class="search mr10 mb10" />
        <el-input v-model="account" style="width: 280px" placeholder="搜尋賬號..." :prefix-icon="Search" class="search mr10 mb10" />
        <el-input v-model="account_name" style="width: 280px" placeholder="搜尋賬戶名稱..." :prefix-icon="Search" class="search mr10 mb10" />
        <el-select v-model="status" placeholder="選擇狀態" size="large" style="width: 240px" class="mb10 mr10">
          <el-option v-for="item in statusOptions" :key="item.label" :label="item.label" :value="item.value" />
        </el-select>
        <el-select v-model="type" placeholder="選擇賬戶類型" size="large" style="width: 240px" class="mb10">
          <el-option v-for="item in typeOptions" :key="item.label" :label="item.label" :value="item.value" />
        </el-select>

      </div>
      <div class="noshrink mb10">
        <el-button class="btn2" @click="search()">查詢</el-button>
        <el-button class="btn1" @click="reset()">重置</el-button>
      </div>
    </div>
    <div class="mt15 radius10 hidden pb15 flex1 bgwhite  flex-col w100p">
      <div class="flex1 w100p ">
        <el-table :data="tableData" style="width: 100%" cell-class-name="tbcell" header-cell-class-name="hdcell">
          <el-table-column prop="uid" label="用戶訊息" min-width="200">
            <template #default="scope">
              <span @click="showUser(scope.row.uid)">{{ scope.row.uid }}(ID:{{ scope.row.uid }})</span>
            </template>
          </el-table-column>
          <el-table-column prop="account" label="賬號" width="200" />
          <el-table-column prop="user" label="手機號" width="200" >
            <template #default="scope">
              <span>{{ scope.row.user?scope.row.user.phone :'' }}</span>
            </template>
          </el-table-column>

          <el-table-column prop="front_view" label="賬戶類型" width="150">
            <template #default="scope">
              <span>{{ scope.row.type == 1 ? '支付寶' : '銀行卡' }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="account_name" label="戶名" width="150" />
          <el-table-column prop="bank_name" label="銀行名稱" width="150" />
          <el-table-column prop="bank_address" label="銀行代號" width="200" />

          <el-table-column prop="" label="審核狀態" width="100">
            <template #default="scope">
              <div class="yellow" v-if="scope.row.status == 0">待審核</div>
              <div class="blue" v-if="scope.row.status == 1">通過</div>
              <div class="red" v-if="scope.row.status == 2">拒絕</div>
            </template>
          </el-table-column>
          <el-table-column prop="adminuser.name" label="審核人" width="150" />
          <el-table-column prop="msg" label="拒絕原因" width="150" />
          <el-table-column prop="created_at" label="創建時間" width="200" />
          <el-table-column prop="" label="操作" width="100" fixed="right">
            <template #default="scope">
              <div class=" pointer" @click="edit(scope.row)">編輯</div>

            </template>
          </el-table-column>
        </el-table>
      </div>
      <div class="plr20 mlauto mt20">
        <el-pagination v-model:current-page="currentPage" prev-text="上一頁" next-text="下一頁" :default-page-size="15" :small="small" :disabled="disabled" :background="true" layout="prev, pager, next, jumper" :total="total" @size-change="handleSizeChange" @current-change="handleCurrentChange" />
      </div>

    </div>
  </div>
</template>

<script setup>
import { Search } from '@element-plus/icons-vue'
import { ref, onMounted } from 'vue'
import { useRouter } from 'vue-router';
import { accountList } from '@/api/usersManage'
import { inject } from 'vue';
const showUser = inject('showUser');
onMounted(() => {
  getAccountList()
})
// 提現列表
const getAccountList = () => {
  accountList({
    page: currentPage.value,
    status: status.value,
    uid: uid.value,
    type: type.value,
    mobile: mobile.value,
    account: account.value,
    account_name: account_name.value
  }).then((res) => {
    console.log('提現列表', res)
    tableData.value = res.data.data
    total.value = res.data.total
    // console.log('tableData', tableData.value)
  })
}
const typeOptions = [
  {
    label: '支付寶',
    value: '1'
  },
  {
    label: '銀行卡',
    value: '2'
  },
]
const statusOptions = [
  {
    label: '審核中',
    value: '0'
  },
  {
    label: '成功',
    value: '1'
  },
  {
    label: '失敗',
    value: '2'
  },
]


const uid = ref('')
const mobile = ref('')
const account = ref('')
const account_name = ref('')
const status = ref('')
const type = ref('')

const dialogTableVisible = ref(false)
const tableData = ref([])
const currentPage = ref(1)
const total = ref(0)
const handleSizeChange = (val) => {
  console.log(`${val} items per page`)
}
const handleCurrentChange = (val) => {
  console.log(`current page: ${val}`)
}
// 搜尋
const search = () => {
  getAccountList()
}
// 重置
const reset = () => {
  status.value = ''
  uid.value = ''
  type.value = ''
  mobile.value = ''
  account.value = ''
  account_name.value = ''
  getAccountList()

}
const router = useRouter()
const edit = (row) => {
  router.push({ path: 'editCash', query: {...row,mobile:row.user?row.user.phone:''} })
}
</script>

<style lang="scss" scoped>
.search {
  overflow: hidden;
  border-radius: 10px !important;
  // padding: 5px 0px;
}

:deep(.el-input__wrapper) {
  box-shadow: none;
}
</style>
<style></style>
 